class Assutils {

    constructor(Vue){
        this._Vue = Vue;
        // 汉字转数字 简单语义化
        this.chnNumChar = {
            零: 0,
            一: 1,
            二: 2,
            三: 3,
            四: 4,
            五: 5,
            六: 6,
            七: 7,
            八: 8,
            九: 9
        };

        this.chnNameValue = {
            十: {
                value: 10,
                secUnit: false
            },
            百: {
                value: 100,
                secUnit: false
            },
            千: {
                value: 1000,
                secUnit: false
            },
            万: {
                value: 10000,
                secUnit: true
            },
            亿: {
                value: 100000000,
                secUnit: true
            }
        }
    }
    /**
     * 车载，中文转写，翻译，句对，听见-文稿-角色 听见-字幕时间戳使用了该js
     * Created by stt on 2018/3/1.
     */
    // /**
    //  * 浏览器默认行为处理
    //  * @param e
    //  */
    // shortkeyPreventAndBubble(e) {
    //     if (e && e.stopPropagation) {
    //         //使用W3C的stopPropagation()方法
    //         e.stopPropagation();
    //     } else {
    //         //使用IE的cancelBubble = true来取消事件冒泡
    //         window.event.cancelBubble = true;
    //     }
    //     if (e && e.preventDefault)
    //         //阻止默认浏览器动作(W3C)
    //         e.preventDefault();
    //     else {
    //         //IE中阻止函数器默认动作的方式
    //         window.event.returnValue = false;
    //     }
    // }


    // /**
    //  *   快捷键判断
    //  * @param isMatch
    //  * @param success
    //  * @param e
    //  */
    // shortKeyIfTrue(isMatch, success, e) {
    //     if (isMatch) {
    //         success();
    //         this.shortkeyPreventAndBubble(e);
    //     }
    // }

    // /**
    //  * 将 s 转换 为固定时间格式
    //  * @param pTime
    //  * @param pPattern
    //  * @returns {*}
    //  */
    // formatTime(pTime, pPattern) {
    //     if (isNaN(pTime) || pTime < 0) {
    //         return '--';
    //     }
    //     if (pPattern == 'HH:mm:ss') {
    //         return [('00' + Math.floor(pTime / 3600)).slice(-2), // hour
    //             ('00' + Math.floor(pTime % 3600 / 60)).slice(-2), // minutes
    //             ('00' + Math.floor(pTime % 60)).slice(-2)
    //         ].join(':'); // seconds
    //     } else if (pPattern == 'HH:mm:ss,SSS') {
    //         return [('00' + Math.floor(pTime / 3600)).slice(-2), // hour
    //             ('00' + Math.floor(pTime % 3600 / 60)).slice(-2), // minutes
    //             ('00' + Math.floor(pTime % 60)).slice(-2), // seconds
    //         ].join(':') + "," + ('000' + Math.floor(pTime * 1000 % 1000)).slice(-3); // ms;
    //     } else {
    //         return pTime;
    //     }
    // }

    // /**
    //  * 将时间转换为yyyy-MM-dd HH:mm:ss
    //  * @param pTime
    //  * @returns {string}
    //  */
    // toDateTime(pTime) {
    //     var date = new Date(pTime),
    //         month = date.getMonth() + 1;
    //     month = month >= 10 ? month : '0' + month;
    //     var day = date.getDate() >= 10 ? date.getDate() : '0' + date.getDate(),
    //         hours = date.getHours() >= 10 ? date.getHours() : '0' + date.getHours(),
    //         minutes = date.getMinutes() >= 10 ? date.getMinutes() : '0' + date.getMinutes(),
    //         seconds = date.getSeconds() >= 10 ? date.getSeconds() : '0' + date.getSeconds();
    //     return date.getFullYear() + '-' + month + '-' + day + ' ' +
    //         hours + ':' + minutes + ':' + seconds;
    // }


    // /**
    //  *  保留3位小数
    //  * @param pTime
    //  * @returns {number}
    //  */
    // handleTime(pTime) {
    //     return Math.floor(pTime * 1000) / 1000;
    // }

    // /**
    //  * 获取元素在数组中的位置
    //  * @param arr
    //  * @param str
    //  * @returns {number}
    //  */
    // indexOf(arr, str) {
    //     // 如果可以的话，调用原生方法
    //     if (arr && arr.indexOf) {
    //         return arr.indexOf(str);
    //     }
    //     var len = arr.length;
    //     for (var i = 0; i < len; i++) {
    //         // 定位该元素位置
    //         if (arr[i] == str) {
    //             return i;
    //         }
    //     }
    //     // 数组中不存在该元素
    //     return -1;
    // }

    // /**
    //  * 判断是否是json
    //  * @param str
    //  * @returns {boolean}
    //  */
    // isJSON(str) {
    //     if (typeof str == 'string') {
    //         try {
    //             var obj = JSON.parse(str);
    //             if (typeof obj == 'object' && obj) {
    //                 return true;
    //             } else {
    //                 return false;
    //             }
    //         } catch (e) {
    //             return false;
    //         }
    //     }
    // }

    // /**
    //  * 预先判断条件是否满足
    //  * @param success
    //  * @param prejudgeMethods
    //  */
    // prejudgeMethodChain(prejudgeMethods, success) {
    //     var len = prejudgeMethods.length,
    //         isOk = true;
    //     for (var i = 0; i < len; i++) {
    //         if (prejudgeMethods[i] != undefined) {
    //             var result = prejudgeMethods[i]();
    //             if (result == undefined || result == false) {
    //                 isOk = false;
    //                 break;
    //             }
    //         }
    //     }
    //     if (isOk) {
    //         return success ? success() : null;
    //     }
    // }

    // prejudgeM(success) {
    //     var prejudeMethods = [];
    //     if (arguments.length > 1) {
    //         for (var i = 1; i < arguments.length; i++) {
    //             prejudeMethods.push(arguments[i]);
    //         }
    //     }
    //     return this.prejudgeMethodChain(prejudeMethods, success);
    // }

    sleep(milliSeconds) {
        var startTime = new Date().getTime();
        while (new Date().getTime() < startTime + milliSeconds);
    }

    // isNotNull(p) {
    //     if (p == undefined || p == null || p == 0 || p == '') {
    //         return false;
    //     }
    //     return true;
    // }

    // isNull(n) {
    //     if (n == undefined || n == null || n == '' || n == '--') {
    //         return true;
    //     }
    //     return false;
    // }

    // /**
    //  * 给指定的元素的指定位置添加焦点 textaera适用
    //  * @param pId
    //  * @param pPosition
    //  */
    // skipFocusPosition(pId, pPosition) {
    //     var elem = document.getElementById(pId);
    //     elem.focus();
    //     if (elem.setSelectionRange) { // 标准浏览器
    //         elem.setSelectionRange(pPosition, pPosition);
    //     } else { // IE9-
    //         var range = elem.createTextRange();
    //         // range.moveStart("character", -len);
    //         // range.moveEnd("character", -len);  不知道哪里来的len by HuiNian
    //         range.moveStart("character", 0);
    //         range.moveEnd("character", 0);
    //         range.moveStart("character", pPosition);
    //         range.moveEnd("character", 0);
    //         range.select();
    //     }
    // }


    /**
     * 播放器组件
     * @param WaveSurfer
     * @param regions
     * @param pId
     * @param pUrl
     * @returns {{isZoom: boolean, isDraging: boolean, resize: boolean, resizeCallback: undefined, resizePrejude: undefined, height: number, interact: boolean, showTitle: boolean, barWidth: number, barHeight: number, resizeStartPrejude: undefined, resizeStartCallback: undefined, resizeEndPrejude: undefined, resizeEndCallback: undefined, initialOffset: number, dragSelection: boolean, ready: ready, pause: pause, click: click, region_click: region_click, region_created: region_created, region_updated: region_updated, region_dblclick: region_dblclick, loading: loading, error: error, finish: finish, addFinishMethod: addFinishMethod, setInteract: setInteract, setBarWidth: setBarWidth, setBarHeight: setBarHeight, setHeight: setHeight, setDragSelection: setDragSelection, setShowTitle: setShowTitle, zoom: zoom, addReadyMethod: addReadyMethod, addPauseMethod: addPauseMethod, addClick: addClick, addRegionDbClickMethod: addRegionDbClickMethod, addRegionClickMethod: addRegionClickMethod, addRegionCreatedMethod: addRegionCreatedMethod, addResize: addResize, addResizeCallback: addResizeCallback, addResizePrejude: addResizePrejude, addResizeStartPrejude: addResizeStartPrejude, addResizeStartCallback: addResizeStartCallback, addResizeEndPrejude: addResizeEndPrejude, addResizeEndCallback: addResizeEndCallback, addOffset: addOffset, addLoading: addLoading, addErrorCallBack: addErrorCallBack, addRegionUpdated: addRegionUpdated, setRegionHandleWidth: setRegionHandleWidth, build: build}}
     */
    playerBuilder(WaveSurfer, regions, pId, pUrl) {

        var player = {
            playIndex: pId,
            currentUrl: pUrl,
            wavesurfer: null,
            loadingValue: '--', // 加载值
            isReady: false, // 音频是否所有都准备完毕
            isStartLoading: true, // 加载上锁，防止重复加载
            currentTime: function () { // 返回s
                return this.handleTime(player.wavesurfer.getCurrentTime() + builder.initialOffset);
            },
            play: function (start, end) { // 普通播放 不绘制区域
                if (start == undefined && end == undefined) { // 正常播放
                    player.wavesurfer.hideCursor(false);
                    player.wavesurfer.play();
                    return;
                }
                start = start - builder.initialOffset;
                end = end - builder.initialOffset;
                player.wavesurfer.play(start, end); // 可以播放指定范围的音频
            },
            pause: function () {
                setTimeout(function () {
                    player.wavesurfer.pause();
                }, 7);
                return player;
            },
            stop: function () {
                player.wavesurfer.pause();
            },
            end: function () {
                player.wavesurfer.stop();
            },
            playRegion: function (start, end) { // 单位s 播放当前区域，如果当前区域的大小是0 则不播放 注意：该方法会改变区域大小，但是没有刷新区域显示
                if (start == undefined) {
                    start = player.wavesurfer.getStartEndUnformat().start;
                }
                if (end == undefined) {
                    end = player.wavesurfer.getStartEndUnformat().end;
                }
                start = start - builder.initialOffset; // 偏移量处理
                end = end - builder.initialOffset;
                player.wavesurfer.playCurrentRegion(start, end);
                return player;
            },
            setRegion: function (start, end) { //
                // 偏移量处理
                start = start - builder.initialOffset;
                end = end - builder.initialOffset;
                player.wavesurfer.setRegionStartAndEnd(start, end);
                return player;
            },
            clearRegions: function () {
                player.setRegion(0, 0); // 设置为0，去除区域
                player.wavesurfer.clearRegions();
                return player;
            },
            // 跳转到该区域，如果正在播放则播放，暂停则暂停
            skipRegion: function (start, end) {
                // 偏移量处理
                var playing = player.isPlaying();
                player.playRegion(start, end);
                if (!playing) {
                    player.pause();
                }
                return player;
            },
            isPlaying: function () {
                return player.wavesurfer.isPlaying();
            },
            getRegionStart: function () {
                return player.wavesurfer.getStartEndUnformat().start;
            },
            getRegionEnd: function () {
                return player.wavesurfer.getStartEndUnformat().end;
            },
            changeWaveSurfer: function () {
                player.wavesurfer.changeWaveSurfer(builder.initialOffset);
            },
            destroy: function () {
                player.isReady = false;
                player.wavesurfer.destroy();
            },
            // 加载url并绘图
            loadUrl: function (pUrl, finishLoad) {
                if (player.isStartLoading) {
                    player.isStartLoading = false;
                    if (builder.showTitle) {
                        this._Vue.$message("音频加载中...");
                    }
                    player.wavesurfer.on("ready", function () {
                        finishLoad ? finishLoad() : '';
                    });
                    player.currentUrl = pUrl ? pUrl : player.currentUrl;
                    player.wavesurfer.load(player.currentUrl);

                    if (builder.isZoom) {
                        // 进行伸缩操作
                        try {
                            player.wavesurfer.zoom(30);
                        } catch (e) {
                            console.log(e);
                        }
                    }
                }
                return player;
            },
            reload: function (pUrl, finishLoad) {
                player.isStartLoading = true;
                player.loadUrl(pUrl, finishLoad);
            },
        };
        var builder = {
            isZoom: true, // 是否伸缩，默认30px/s
            isDraging: false,
            resize: false, // 是否可用拖动
            resizeCallback: undefined,
            resizePrejude: undefined, //
            height: 120,
            interact: false,
            showTitle: true, // 是否显示提示
            barHeight: 1,
            resizeStartPrejude: undefined, //
            resizeStartCallback: undefined,
            resizeEndPrejude: undefined,
            resizeEndCallback: undefined,

            initialOffset: 0, // 设置该player的起始偏移量 单位s 总偏移量,
            dragSelection: false, // 是否手动绘图

            ready: function () {},
            pause: function () {},
            click: function () {},
            region_click: function () {},
            region_created: function () {},
            region_updated: function () {},
            region_dblclick: function () {},
            loading: function () {},
            error: function () {},
            finish: function () {},


            addFinishMethod: function (pFinish) {
                builder.finish = pFinish;
                return builder;
            },
            setInteract: function (pInteract) {
                builder.interact = pInteract;
                return builder;
            },
            setBarWidth: function (barWidth) {
                builder.barWidth = barWidth;
                return builder;
            },
            setBarHeight: function (barHeight) {
                builder.barHeight = barHeight;
                return builder;
            },
            setHeight: function (pHeight) {
                builder.height = pHeight;
                return builder;
            },
            setDragSelection: function (pDrag) {
                builder.dragSelection = pDrag;
                return builder;
            },
            setShowTitle: function (pShowTitle) {
                builder.showTitle = pShowTitle;
                return builder;
            },
            zoom: function (pZoom) {
                builder.isZoom = pZoom;
                return builder;
            },
            addReadyMethod: function (pReady) {
                builder.ready = pReady;
                return builder;
            },
            addPauseMethod: function (pPause) {
                builder.pause = pPause;
                return builder;
            },
            addClick: function (pClick) {
                builder.click = pClick;
                return builder;
            },
            addRegionDbClickMethod: function (pMethod) {
                builder.region_dblclick = pMethod;
                return builder;
            },
            addRegionClickMethod: function (pRegion_click) {
                builder.region_click = pRegion_click;
                return builder;
            },
            addRegionCreatedMethod: function (pRegionCreated) {
                builder.region_created = pRegionCreated;
                return builder;
            },
            addResize: function (pResize) {
                builder.resize = pResize;
                return builder;
            },
            addResizeCallback: function (pResizeCallback) {
                builder.resizeCallback = pResizeCallback;
                return builder;
            },
            // 拖拽条件限制
            addResizePrejude: function (pResizePrejude) {
                builder.resizePrejude = pResizePrejude;
                return builder;
            },
            addResizeStartPrejude: function (pResizeStartPrejude) {
                builder.resizeStartPrejude = pResizeStartPrejude;
                return builder;
            },
            addResizeStartCallback: function (pResizeStartCallback) {
                builder.resizeStartCallback = pResizeStartCallback;
                return builder;
            },
            addResizeEndPrejude: function (pResizeEndPrejude) {
                builder.resizeEndPrejude = pResizeEndPrejude;
                return builder;
            },
            addResizeEndCallback: function (pResizeEndCallback) {
                builder.resizeEndCallback = pResizeEndCallback;
                return builder;
            },
            addOffset: function (pInitialOffset) {
                builder.initialOffset = pInitialOffset;
                return builder;
            },
            addLoading: function (pLoading) {
                builder.loading = pLoading;
                return builder;
            },
            addErrorCallBack: function (pError) {
                builder.error = pError;
                return builder;
            },
            addRegionUpdated: function (regionUpdated) {
                builder.region_updated = regionUpdated;
                return builder;
            },
            setRegionHandleWidth: function (regionHandleWidth) {
                builder.regionHandleWidth = regionHandleWidth;
                return builder;
            },
            build: function () {
                // 初始化音频插件
                // 支持：aac flac m4r ogg wav mp3 opus
                // 不支持：ac3 amr ape mmf mp2 wv wma pcm
                player.wavesurfer = WaveSurfer.create({
                    container: '#' + pId,
                    cursorColor: '#fcad1d',
                    waveColor: '#579676',
                    progressColor: '#08dc8c',
                    // backend: 'MediaElement', // wav在谷歌下不可片段播放
                    height: builder.height,
                    pixelRatio: 1,
                    scrollParent: true,
                    hideScrollbar: true,
                    interact: builder.interact, // 线的交互,
                    click: builder.click, // 点击事件
                    barWidth: builder.barWidth,
                    barHeight: builder.barHeight,
                    plugins: [
                        regions.create({
                            regions: [{
                                drag: false,
                                start: 0,
                                end: 0,
                                color: 'rgba(180, 192, 110, 0.498)',
                                resize: builder.resize,
                                regionHandleWidth: builder.regionHandleWidth,
                                resizeCallback: builder.resizeCallback,
                                resizePrejude: builder.resizePrejude,
                                resizeStartPrejude: builder.resizeStartPrejude,
                                resizeStartCallback: builder.resizeStartCallback,
                                resizeEndPrejude: builder.resizeEndPrejude,
                                resizeEndCallback: builder.resizeEndCallback,
                                initialOffset: builder.initialOffset,
                                regionUpdated: builder.region_updated,

                                dragOnDown: function () {
                                    builder.isDraging = true;
                                },
                                dragOnUp: function () {
                                    builder.isDraging = false;
                                }
                            }, ],
                            dragSelection: builder.dragSelection,
                        }),
                    ]
                }, player.wavesurfer);

                // 加载完成后并播放
                player.wavesurfer.on("ready", function () {
                    if (builder.showTitle) {
                        this._Vue.$message("音频加载完成");
                    }
                    player.isReady = true;
                    builder.ready();
                });
                player.wavesurfer.on('finish', function () {
                    builder.finish();
                });
                player.wavesurfer.on("pause", function () {
                    builder.pause();
                });
                // 鼠标移动到播放区域
                player.wavesurfer.on("region-mouseenter", function () {
                    if (!builder.interact) {
                        // 不可交互，但特殊时 控制帧只有在区域内可以移动
                        player.wavesurfer.toggleInteraction();
                    }
                });
                player.wavesurfer.on("region-mouseleave", function () {
                    if (!builder.interact) {
                        player.wavesurfer.toggleInteraction();
                    }
                });
                player.wavesurfer.on("region-click", function () {
                    builder.region_click();
                });

                player.wavesurfer.on("region-dblclick", function () {
                    builder.region_dblclick();
                });

                player.wavesurfer.on("loading", function (e) {
                    player.loadingValue = e;
                    if (e == 100 && builder.showTitle) {
                        this._Vue.$message("音频加载完毕，开始绘制图形");
                    }
                    builder.loading(player);
                });
                var retryTimes = 5; // 加载异常重试次数
                player.wavesurfer.on("error", function (e) {
                    if (retryTimes >= 0) {
                        player.wavesurfer.load(player.currentUrl);
                        retryTimes--;
                    } else {
                        retryTimes = 5;
                        this._Vue.$message(e + "加载音频异常");
                        builder.error();
                    }
                });

                return player;
            }
        };
        return builder;

    }
    // /**
    //  * 跳转url
    //  * @param pUrl
    //  */
    // jumpUrl(pUrl) {
    //     window.location.href = pUrl;
    // }

    // /**
    //  * 给url添加参数
    //  * @param pUrl
    //  * @param uriParam
    //  * @returns {string}
    //  */
    // addUriParam(pUrl, uriParam) {
    //     var url = pUrl + '?';
    //     for (var key in uriParam) {
    //         url = url + key + '=' + uriParam[key] + '&';
    //     }
    //     return url;
    // }

    /**
     * 数字转中文 如100 转 幺零零
     * @param num
     * @param isOneToYao
     * @returns {*}
     * @constructor
     */
    NumberToChineseChar(num, isOneToYao) {
        var nubmer = ["零", "幺", "二", "三", "四", "五", "六", "七", "八", "九"],
            val = num;
        if (val.indexOf("1") != -1) {
            if (!isOneToYao) {
                nubmer[1] = "一";
            }
        }
        for (var i = 0; i < 10; i++) {
            var regex = new RegExp("" + i, "g");
            val = val.replace(regex, nubmer[i]);
        }
        return val;
    }
    /**
     * 中文一转幺 如一百 转 幺百
     * @param numCn
     * @param isOneToYao
     * @returns {*}
     * @constructor
     */
    ChineseToNumberChar(numCn, isOneToYao) {
        if (isOneToYao) {
            return numCn.replace(/幺/g, '1')
        }

        var number = ["零", ['幺', '一'], "二", "三", "四", "五", "六", "七", "八", "九"],
            cnNun = numCn;

        number.forEach(function (item, ind) {
            var cnStr = number[ind];
            if (typeof cnStr != 'string') {
                return cnStr.forEach(function (item) {
                    var regex = new RegExp(item, 'g');
                    cnNun = cnNun.replace(regex, ind)
                })
            }
            var regex = new RegExp(item, 'g');
            cnNun = cnNun.replace(regex, ind)
        });
        return cnNun
    }
    /**
     * 数字转中文含义，如100 转一百
     * @param num
     * @returns {*}
     * @constructor
     */
    NumberToChineseSound(num) {
        var regex = /\d+(\.\d+)?/g;
        let result = regex.exec(num);
        while (result != null) {
            result = result[0];
            var newResult = this.Arabia_to_Chinese(result);
            num = num.replace(result, newResult);
        }
        return num;
    }

    /**
     * 数字转中文语义
     * @param Num
     * @returns {*}
     * @constructor
     */
    Arabia_to_Chinese(Num) {
        for (let i = Num.length - 1; i >= 0; i--) {
            Num = Num.replace(",", "");
            Num = Num.replace(" ", "");
        }
        //---字符处理完毕，开始转换，转换采用前后两部分分别转换---//
        let part = String(Num).split(".");
        let newchar = "";
        //小数点前进行转化
        for (let i = part[0].length - 1; i >= 0; i--) {
            if (part[0].length > 10) {
                return Num;
            } //若数量超过拾亿单位，提示
            let tmpnewchar = "";
            let perchar = part[0].charAt(i);
            switch (perchar) {
                case "0":
                    tmpnewchar = "零" + tmpnewchar;
                    break;
                case "1":
                    tmpnewchar = "一" + tmpnewchar;
                    break;
                case "2":
                    tmpnewchar = "二" + tmpnewchar;
                    break;
                case "3":
                    tmpnewchar = "三" + tmpnewchar;
                    break;
                case "4":
                    tmpnewchar = "四" + tmpnewchar;
                    break;
                case "5":
                    tmpnewchar = "五" + tmpnewchar;
                    break;
                case "6":
                    tmpnewchar = "六" + tmpnewchar;
                    break;
                case "7":
                    tmpnewchar = "七" + tmpnewchar;
                    break;
                case "8":
                    tmpnewchar = "八" + tmpnewchar;
                    break;
                case "9":
                    tmpnewchar = "九" + tmpnewchar;
                    break;
            }
            switch (part[0].length - i - 1) {
                case 0:
                    tmpnewchar = tmpnewchar + "";
                    break;
                case 1:
                    if (perchar != 0) tmpnewchar = tmpnewchar + "十";
                    break;
                case 2:
                    if (perchar != 0) tmpnewchar = tmpnewchar + "百";
                    break;
                case 3:
                    if (perchar != 0) tmpnewchar = tmpnewchar + "千";
                    break;
                case 4:
                    tmpnewchar = tmpnewchar + "万";
                    break;
                case 5:
                    if (perchar != 0) tmpnewchar = tmpnewchar + "十";
                    break;
                case 6:
                    if (perchar != 0) tmpnewchar = tmpnewchar + "百";
                    break;
                case 7:
                    if (perchar != 0) tmpnewchar = tmpnewchar + "千";
                    break;
                case 8:
                    tmpnewchar = tmpnewchar + "亿";
                    break;
                case 9:
                    tmpnewchar = tmpnewchar + "十";
                    break;
            }
            newchar = tmpnewchar + newchar;
        }
        //小数点之后进行转化
        if (Num.indexOf(".") != -1) {
            newchar += "点";
            for (let i = 0; i < part[1].length; i++) {
                let tmpnewchar = ""
                let perchar = part[1].charAt(i)
                switch (perchar) {
                    case "0":
                        tmpnewchar = "零" + tmpnewchar;
                        break;
                    case "1":
                        tmpnewchar = "一" + tmpnewchar;
                        break;
                    case "2":
                        tmpnewchar = "二" + tmpnewchar;
                        break;
                    case "3":
                        tmpnewchar = "三" + tmpnewchar;
                        break;
                    case "4":
                        tmpnewchar = "四" + tmpnewchar;
                        break;
                    case "5":
                        tmpnewchar = "五" + tmpnewchar;
                        break;
                    case "6":
                        tmpnewchar = "六" + tmpnewchar;
                        break;
                    case "7":
                        tmpnewchar = "七" + tmpnewchar;
                        break;
                    case "8":
                        tmpnewchar = "八" + tmpnewchar;
                        break;
                    case "9":
                        tmpnewchar = "九" + tmpnewchar;
                        break;
                }
                newchar = newchar + tmpnewchar;
            }
        }
        //替换所有无用汉字
        while (newchar.search("零零") != -1) {
            newchar = newchar.replace("零零", "零");
        }
        newchar = newchar.replace("零亿", "亿");
        newchar = newchar.replace("亿万", "亿");
        newchar = newchar.replace("零万", "万");
        newchar = newchar.replace("十零", "十");

        if (newchar[newchar.length - 1] == "零") {
            newchar = newchar.substr(0, newchar.length - 1);
        }
        if (newchar.substr(0, 2) == "一十") {
            newchar = newchar.substr(1);
        }
        return newchar;
    }


    /**
     * 进度条
     * @param id
     * @constructor
     */

    Progress(id, max) {

        var _this = this;
        this.interact = true;
        this.fixedNodes = null; // 初始化点 固定点 一个数组对象，包含相对于max的值

        var progress = document.getElementById(id);
        progress.className = "progress";
        var mask = document.createElement("div");
        mask.className = "progress-mask";
        var bar = document.createElement("div");
        bar.className = "progress-bar";
        progress.appendChild(mask);
        progress.appendChild(bar);

        _this.curProgress = function () {}; // 返回当前进度
        _this.curValue = function () {}; // 返回当前数值

        _this.setProgress = function (p) {
            p = p > 100 ? 100 : p;
            mask.style.width = p + '%';
            var x = p * totalLength() / 100;
            bar.style.left = x + 'px';
        };
        _this.setValue = function (v) {
            if (!isNaN(max) && max != 0 && !isNaN(v)) {
                _this.setProgress(v * 100 / max);
            }
            bar.setAttribute("title", _this.formatTime(v, 'HH:mm:ss,SSS'));
        };
        this.setInteract = function (val) {
            _this.interact = val;
            return _this;
        };
        this.loadNodes = function (nodes) {
            _this.fixedNodes = nodes;
            if (_this.fixedNodes != null && _this.fixedNodes.length != 0 && !isNaN(max) && max != 0) { // 画固定点
                for (var i = 0; i < _this.fixedNodes.length; i++) {
                    var node = document.createElement("div"),
                        v = _this.fixedNodes[i].val;
                    node.className = "progress-node";
                    node.setAttribute("title", _this.formatTime(v, 'HH:mm:ss,SSS'));
                    progress.appendChild(node);

                    var x = v * (node.offsetParent.offsetWidth - node.offsetWidth) / max;
                    node.style.left = x + 'px';
                }
            }
            return _this;
        };
        this.build = function () {
            if (_this.interact) {
                progress.onclick = function (event) {
                    let e = event || window.event;
                    locate(e.clientX - this.offsetLeft);
                };
                bar.onmousedown = function (event) {
                    let _event = event || window.event;
                    // 获取鼠标按下的初始距离
                    // 此处的offsetLeft是距离父级元素的距离（直接的绝对定位的父级），因为父级元素可能会有嵌套
                    var leftVal = _event.clientX - this.offsetLeft;
                    document.onmousemove = function (event) {
                        let _event = event || window.event;
                        locate(_event.clientX - leftVal);
                    };
                    // 注意要在document对象的onmouseup方法
                    document.onmouseup = function () {
                        // 当鼠标释放点击后，移动函数设置为null
                        document.onmousemove = null;
                    };
                };
            }

            return _this;
        };

        function locate(x) {
            if (x < 0) x = 0;
            if (x > totalLength()) {
                x = totalLength();
            }
            bar.style.left = x + 'px';
            // 重要：解决选择div中的内容，去除选择，防止拖动的时候失效
            window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
            // 计算百分比
            var p = x * 100 / (totalLength());
            mask.style.width = (p > 100 ? 100 : p) + '%';

            _this.curProgress(p);
            if (!isNaN(max)) {
                _this.curValue(p * max / 100);
            }
        }

        function totalLength() {
            return bar.offsetParent.offsetWidth - bar.offsetWidth;
        }
    }
    // /**
    //  * 缓存
    //  * @param key
    //  * @param value
    //  * @returns {*}
    //  */
    // getsetCacheValue(id, value) {
    //     // 缓存处理
    //     var key = "markTask_history";
    //     var cache = window.localStorage.getItem(key);
    //     cache = this.isNull(cache) ? {} : JSON.parse(cache);
    //     var result = null;
    //     if (this.isNotNull(cache[id])) {
    //         result = cache[id].value;
    //     }
    //     // 没有变化也不进行操作
    //     if (this.isNull(value) || JSON.stringify(value) == JSON.stringify(result)) {
    //         return result;
    //     }
    //     cache[id] = {
    //         value: value,
    //         date: new Date().getTime()
    //     };
    //     let deleteKeys = [];
    //     for (let k in cache) {
    //         if (k != id && this.isNotNull(cache[k].date)) {
    //             let now = new Date().getTime();
    //             if (now - cache[k].date >= 7 * 24 * 60 * 60 * 1000) { // 超过7周，去除
    //                 deleteKeys.push(k);
    //             }
    //         }
    //     }
    //     for (let key in deleteKeys) {
    //         delete cache[key];
    //     }
    //     window.localStorage.setItem(key, JSON.stringify(cache));
    //     return result;
    // }

    // /**
    //  * 自适应 textarea高度
    //  * @param el
    //  * @param height
    //  */
    // makeExpandingArea(el, height) {
    //     if (height == undefined) height = 'auto';
    //     el.style.height = height;
    //     el.style.height = (el.scrollHeight) + "px";
    // }

    
    // 中文轉數字
    ChineseToNumber(chnStr) {
        var rtn = 0;
        var section = 0;
        var number = 0;
        var secUnit = false;
        var str = chnStr.split('');

        for (var i = 0; i < str.length; i++) {
            var num = this.chnNumChar[str[i]];
            if (typeof num !== 'undefined') {
                number = num;
                if (i === str.length - 1) {
                    section += number;
                }
            } else {
                var unit = this.chnNameValue[str[i]] ? this.chnNameValue[str[i]].value : '';
                secUnit = this.chnNameValue[str[i]] ? this.chnNameValue[str[i]].secUnit : '';
                if (secUnit) {
                    section = (section + number) * unit;
                    rtn += section;
                    section = 0;
                } else {
                    section += (number * unit);
                }
                number = 0;
            }
        }
        return rtn + section;
    }

    // 中文转数字
    Conversion() {
        // 记录个、十、百、...亿每一位的数字，一共9位
        this.num_money = []
        // 钱中数量单位
        this.mon = ['十', '百', '千', '万', '亿']
        // 判断数字是否是正确标准的,1:标准的数字, 0:不标准的数字
        this.isRightNum = 1

        /*
         *  函数作用：判断m_str中有没有数字，并将数字存入num_money中。没有数字，存0
             :param m_str: 输入汉字钱的字符串，并存入列表中
             :return: 无
          */
        this.char2digit = function (m_str) {
            var money = 0;
            if (m_str.indexOf('一') !== -1 || m_str.indexOf('1') !== -1) {
                money = 1
            } else if (m_str.indexOf('二') !== -1 || m_str.indexOf('2') !== -1 || m_str.indexOf('两') !== -1) {
                money = 2
            } else if (m_str.indexOf('三') !== -1 || m_str.indexOf('3') !== -1) {
                money = 3
            } else if (m_str.indexOf('四') !== -1 || m_str.indexOf('4') !== -1) {
                money = 4
            } else if (m_str.indexOf('五') !== -1 || m_str.indexOf('5') !== -1) {
                money = 5
            } else if (m_str.indexOf('六') !== -1 || m_str.indexOf('6') !== -1) {
                money = 6
            } else if (m_str.indexOf('七') !== -1 || m_str.indexOf('7') !== -1) {
                money = 7
            } else if (m_str.indexOf('八') !== -1 || m_str.indexOf('8') !== -1) {
                money = 8
            } else if (m_str.indexOf('九') !== -1 || m_str.indexOf('9') !== -1) {
                money = 9
            } else {
                money = 0
            }
            this.num_money.push(money) // append 针对 python 的 list 相当于 js 中 arr 的 push
        }

        /*
          * 函数作用：将m_str以'亿，万，千，百，十'为分割区间分成左右两个部分
              :param num: 类型int，用于提取mon［num］中的值，即提取钱的某一个数量单位
              :param m_str: 输入汉字钱的字符串，并存入列表中
              :return: 返回m_str被分成的俩个值
              例子：cut（2，［'五','千','五','百'］）
                   返回：［'五'］，［'五'，'百'］
           */
        this.cut = function (num, m_str) {
            var a = this.mon[num]
            var ind = m_str.indexOf(a)
            var m_left = m_str.slice(0, ind)
            var m_right = m_str.slice(ind + 1, m_str.length)
            return [m_left, m_right]
        }


        /*
         * 计算m_str中数字的个数, 为了处理一千二,一万二这样特殊的情况
             当个数为1时,满足一千二这种特殊情况
             :param m_str: 存钱字符的列表
             :return num: 返回m_str中数字的个数
         */
        this.func3 = function (m_str) {
            var num = 0
            var _str = ['零', '0', '一', '1', '二', '两', '2', '三', '3', '四', '4', '五', '5', '六', '6', '七', '7', '八', '8', '九', '9']
            // enumerate 类js数组 返回 key 和 value
            for (var i = 0; i < m_str.length; i++) {
                if (_str.indexOf(m_str[i]) > -1) {
                    num += 1
                }
            }

            return num
        }

        /*
          * 判断m_str是否是纯数字
              :param m_str: 存钱字符的列表
              :return num: 返回m_str中数字的个数
           */
        this.func4 = function (num, m_str) {
            /*
            * 判断m_str是否是纯数字
                :param m_str: 存钱字符的列表
                :return num: 返回m_str中数字的个数
             */
            var _str = m_str
            if (isNaN(_str)) {
                this.isRightNum = 0
            } else {
                var _num = Number(_str)
                this.isRightNum = 1
                for (var i = 0; i < num; i++) {
                    var _n = Math.pow(10, num - i)
                    var num1 = Number(_num / _n) // 千万位的数字
                    this.num_money.push(num1)
                    _num -= (num1 * _n)
                }
                this.num_money.push(_num)
            }
        }


        /*
         *  该功能的主要函数.
         *  通过递归的方式来汉字钱根据关键字(万,千...)进行划分,然后进行转换
         * */
        this.fact = function (a, m_str) {
            var numTarget = ['一', '二', '两', '三', '四', '五', '六', '七', '八', '九', '十', '百', '千']
            if (a < 0) {
                this.char2digit(m_str)
            } else {
                if (m_str.indexOf(this.mon[a]) > -1) {
                    var m_arr = this.cut(a, m_str)
                    var m_left = m_arr[0]
                    var m_right = m_arr[1]
                    if (this.mon[a] === '十') {
                        if (m_left === ['零'] || m_left === []) {
                            m_left = ['一']
                        }
                    }
                    if (this.mon[a] === '万') {
                        // 判断左边字符串是不是纯数字
                        var boo = true;
                        var boo2 = true;
                        for (var i = 0; i < numTarget.length; i++) {
                            if (m_left.indexOf(numTarget[i]) === -1) { // 不存在
                                boo = boo && true;
                            } else {
                                boo = boo && false
                            }
                        }

                        if (boo) { // true
                            this.func4(a, m_left)
                        } else {
                            this.fact(2, m_left)
                        }
                    } else {
                        this.char2digit(m_left)
                    }


                    // 针对一万二,一千二等特殊情况
                    if (this.func3(m_right) === 1) {
                        this.char2digit(m_right)
                        if (a === 4) {
                            this.addNumMoney(1, 8)
                        }
                        if (a === 3) {
                            this.addNumMoney(1, 4)
                        }
                        if (a === 2) {
                            this.addNumMoney(1, 3)
                        }
                        if (a === 1) {
                            this.num_money.push(0)
                        }
                    } else {
                        for (var j = 0; j < numTarget.length; j++) {
                            if (m_right.indexOf(numTarget[j]) === -1) { // 不存在
                                boo2 = boo2 && true;
                            } else {
                                boo2 = boo2 && false
                            }
                        }
                        if (m_right.length > 0) {
                            boo2 = boo2 && true;
                        } else {
                            boo2 = boo2 && false;
                        }

                        if (boo2) {
                            if (m_right.indexOf('零') > -1) {
                                m_right = m_right.slice(1, m_right.length)
                            }
                            if (m_right.indexOf('块') > -1 || m_right.indexOf('元') > -1) {
                                m_right = m_right.slice(0, -1)
                            }
                            if (m_right.length > 0) {
                                this.func4(a, m_right)
                            }
                        } else {
                            this.fact(a - 1, m_right)
                        }
                    }
                } else {
                    if (a === 3) {
                        this.num_money.push(0)
                        this.num_money.push(0)
                        this.num_money.push(0)
                        this.num_money.push(0)
                    } else {
                        m_left = '0'
                        this.char2digit(m_left)
                    }
                    this.fact(a - 1, m_str)
                }
            }
        }

        /*
        *
        * 先判断有没有'毛'或者'角',先处理毛角的情况,再处理其他部分
              :param num:
              :param m_str:
              :return:
         */
        this.func5 = function (num, m_str) {
            var new_str
            if ((m_str.indexOf('分') > -1 && m_str.indexOf('角') > -1) || (m_str.indexOf('分') > -1 && m_str.indexOf('毛') > -1)) {
                new_str = m_str.slice(0, -4)
                this.fact(num, new_str)
                this.char2digit(m_str[m_str.length - 4])
                this.char2digit(m_str[m_str.length - 2])
            } else if (m_str.indexOf('分') > -1 && m_str.indexOf('角') === -1 && m_str.indexOf('毛') === -1) {
                new_str = m_str.slice(0, -2)
                this.fact(num, new_str)
                this.num_money.push(0)
                this.char2digit(m_str[m_str.length - 2])
            } else if (m_str.indexOf('分') === -1 && (m_str.indexOf('毛') > -1 || m_str.indexOf('角') > -1)) {
                new_str = m_str.slice(0, -2)
                this.fact(num, new_str)
                this.char2digit(m_str[m_str.length - 2])
            } else {
                this.fact(num, m_str)
            }
        }

        this.integrate = function (num, m_str) {
            // 纯数字
            var numTarget = ['一', '二', '两', '三', '四', '五', '六', '七', '八', '九', '十', '百', '千', '万', '亿']
            var boo = true
            for (var i = 0; i < numTarget.length; i++) {
                if (m_str.indexOf(numTarget[i]) === -1) { // 不存在
                    boo = boo && true;
                } else {
                    boo = boo && false
                }
            }
            if (boo) {
                if (m_str.indexOf('块') > -1) {
                    var ind = m_str.indexOf('块')
                    var m_left = m_str.slice(0, ind)
                    var m_right = m_str.slice(ind + 1)
                    var str1 = m_left.join('')
                    var money1 = parseFloat(str1)
                    if (m_right.length > 0) {
                        this.func5(num, m_right)
                        var money2 = this.num2money(this.num_money)
                        return money1 + money2
                    } else {
                        return money1
                    }
                } else if (m_str.indexOf('元') > -1) {
                    let ind = m_str.indexOf('元')
                    let m_left = m_str.slice(0, ind)
                    let m_right = m_str.slice(ind + 1)
                    let str1 = m_left.join('')
                    let money1 = parseFloat(str1)
                    if (m_right.length > 0) {
                        this.func5(num, m_right)
                        let money2 = this.num2money(this.num_money)
                        return money1 + money2
                    } else {
                        return money1
                    }
                } else if (m_str.indexOf('角') === -1 && m_str.indexOf('毛') === -1 && m_str.indexOf('分') === -1) {
                    let str1 = m_str.join('')
                    let money = parseFloat(str1)
                    return money
                } else {
                    this.func5(num, m_str)
                    let money = this.num2money(this.num_money)
                    return money
                }
            } else {
                this.func5(num, m_str)
                var money = this.num2money(this.num_money)
                return money
            }
        }

        this.num2money = function (liststr) {
            var _money = 0
            for (var i = 0; i < liststr.length; i++) {
                var m = liststr[i] * Math.pow(10, 8 - i)
                _money += m
            }
            return _money
        }

        this.mainfunc = function (m_str) {
            this.num_money = []
            // var start = Date.parse(new Date()) / 1000 定义了没有用  by huinian
            var num = 4
            var liststr = m_str // 数组
            var money = this.integrate(num, liststr)
            money = parseFloat(money)
            // var end = Date.parse(new Date()) / 1000 定义了没有用  by huinian
            return money
        }
        // this.num_money 添加
        this.addNumMoney = function (start, end) {
            for (var i = start; i < end; i++) {
                this.num_money.push(0)
            }
        }
    }

    WebsocketService(url) {
        var _this = this;
        this.url = "ws://" + location.hostname + ":" + location.port + url;
        // this.receive = function (msg) {}; by huinian
        this.receive = function () {};
        this.websocket = initWebSocket(this.url);

        function initWebSocket(url) {
            var ws = new WebSocket(url);
            ws.onerror = function (e) {
                console.log(e);
            };
            ws.onopen = function () {};
            ws.onclose = function () {};
            ws.onmessage = function (e) {
                _this.receive(e.data);
            };
            return ws;
        }

        this.send = function (msg) {
            waitForSocketConnection(function () {
                try {
                    _this.websocket.send(msg);
                } catch (e) {
                    console.log(e);
                }
            });
        };
        this.close = function () {
            _this.websocket.close();
        };

        function waitForSocketConnection(callback) {
            setTimeout(
                function () {
                    if (_this.websocket.readyState === 1) {
                        callback !== undefined ? callback() : '';
                        return;
                    } else if (_this.websocket.readyState === 3) {
                        _this.close();
                        _this.websocket = initWebSocket(_this.url);
                    }
                    waitForSocketConnection(callback);
                }, 5);
        }

        return _this;
    }
    
}
export { Assutils }